package com.baizhi.springboot.service.impl;

import com.baizhi.springboot.dao.AudioDao;
import com.baizhi.springboot.entity.Audio;
import com.baizhi.springboot.service.AudioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Transactional
public class AudioServiceImpl implements AudioService {
    @Autowired
    private AudioDao audioDao;
    @Override
    @Transactional(readOnly = true)
    public Map selectAudioByPage(Integer page, Integer limit,Integer albumId) {
        Integer offset=(page-1)*limit;
        List<Audio> audios = audioDao.selectAudioByPage(offset, limit,albumId);
        Integer count = audioDao.selectCount();
        /* "code": 0,
          "msg": "",
          "count": 1000,
          "data": [{}, {}]*/
        HashMap<Object, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", audios);
        return map;
    }

    @Override
    public void insertAudio(Audio audio) {
        audioDao.insertAudio(audio);
    }

    @Override
    public void deleteAudio(Integer id) {
        audioDao.deleteAudio(id);
    }
}
